package cht;

import static org.junit.Assert.assertEquals;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.testing.RobotTestBed;

/**
 * Tests whether to see if the Narchi robot can effectively beat SittingDuck.
 * 
 * @author Terrence Chida
 * 
 */
public class TestNarchiVersusSittingDuck extends RobotTestBed {

  /**
   * Specifies that SittingDuck and Narchi are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.SittingDuck,cht.Narchi";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that Narchi has won every round against SittingDuck.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] battleResults = event.getIndexedResults();
    // Sanity check that results[1] is Narchi (not strictly necessary, but illustrative).
    BattleResults narchiResults = battleResults[1];
    String robotName = narchiResults.getTeamLeaderName();
    assertEquals("Check that results[1] is Narchi", robotName, "cht.Narchi*");

    // Check to make sure Narchi won every round.
    assertEquals("Check Narchi winner", narchiResults.getFirsts(), getNumRounds());
  }

  /**
   * Returns a comma or space separated list like: x1,y1,heading1, x2,y2,heading2, which are the
   * coordinates and heading of robot #1 and #2. So "0,0,180, 50,80,270" means that robot #1 has
   * position (0,0) and heading 180, and robot #2 has position (50,80) and heading 270.
   * 
   * Override this method to explicitly specify the initial positions for your test cases.
   * 
   * Defaults to null, which means that the initial positions are determined randomly. Since battles
   * are deterministic by default, the initial positions are randomly chosen but will always be the
   * same each time you run the test case.
   * 
   * @return The list of initial positions.
   */
  @Override
  public String getInitialPositions() {
    return null;
  }

  /**
   * Returns true if the battle should be deterministic and thus robots will always start in the
   * same position each time.
   * 
   * Override to return false to support random initialization.
   * 
   * @return True if the battle will be deterministic.
   */
  @Override
  public boolean isDeterministic() {
    return true;
  }

  /**
   * Specifies how many errors you expect this battle to generate. Defaults to 0. Override this
   * method to change the number of expected errors.
   * 
   * @return The expected number of errors.
   */
  @Override
  protected int getExpectedErrors() {
    return 0;
  }

} // end TestNarchiVersusSittingDuck
